package campus.aiit.ssl.controller;

import campus.aiit.ssl.domain.model.Strategy;
import campus.aiit.ssl.domain.model.Week;
import campus.aiit.ssl.service.StrategyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * Strategy Management
 *
 * @author ihaokun
 * @date 2019/12/24 9:21
 */
@Api(description = "策略相关api")
@RestController
public class StrategyController {

  @Resource
  private StrategyService strategyService;

  @ApiOperation("添加空调策略")
  @PostMapping("strategies")
  public boolean addStrategy(@RequestBody @Valid Strategy strategy){
    return strategyService.addStrategy(strategy);
  }

  @ApiOperation("修改空调策略")
  @PutMapping("strategies")
  public boolean modifyStrategy(@RequestBody @Valid Strategy strategy){
    return strategyService.saveStrategy(strategy);
  }

  @ApiIgnore()
  @SuppressWarnings("弃用，旧思路")@Deprecated@PutMapping("strategies/day")
  public boolean modifyDay(@RequestBody Week week){
    return strategyService.saveDay(week);
  }

  @ApiOperation("应用空调策略")
  @PostMapping("strategies/apply")
  public boolean apply(@RequestParam long strategyId, @RequestParam long[] deviceIds) throws InterruptedException {
    return strategyService.apply(strategyId, deviceIds);
  }

  // 思路修改，原策略列表接口会被废弃
  @ApiOperation("获取空调策略列表")
  @GetMapping("strategies")
  public List<Strategy> strategies(){
    return strategyService.strategies();
  }

  // 新用户策略列表：可以看见自己和所有管理员设定的策略列表
  @ApiIgnore()
  @GetMapping("strategiesByUser")
  public List<Strategy> strategiesByUser(String userId){
    return strategyService.strategiesByUser();
  }
  // 新管理员策略列表：只能看见自己的策略列表
  @ApiOperation("获取管理员的空调策略列表")
  @GetMapping("strategiesByAdmin")
  public List<Strategy> strategiesByAdmin(String userId){
    return strategyService.strategiesByAdmin();
  }

  @ApiOperation("通过空调策略id获取空调策略")
  @GetMapping("strategies/{id}/days")
  public List<Week> weeks(@PathVariable long id){
    return strategyService.weeks(id);
  }

  @ApiOperation("删除空调策略")
  @DeleteMapping("strategies/{id}")
  public boolean removeStrategy(@PathVariable long id){
    return strategyService.removeStrategy(id);
  }

  //非空调设备
  @ApiOperation("获取非空调策略列表")
  @GetMapping("currencyStrategy/{deviceTypeId}")
  public List<Map<String,Object>> getStrategyByTypeId(@PathVariable long deviceTypeId){
    return strategyService.getStrategyByTypeId(deviceTypeId);
  }

  @ApiOperation("删除非空调策略列表")
  @DeleteMapping("currencyStrategy/{id}")
  public int delCurrencyStrategy(@PathVariable long id){
    return strategyService.delCurrencyStrategy(id);
  }

  @ApiOperation("修改非空调策略列表")
  @PutMapping("currencyStrategy")
  public int updateCurrencyStrategy(@RequestBody Map map) {
    return strategyService.updateCurrencyStrategy(map);
  }

  @ApiOperation("添加非空调策略列表")
  @PostMapping("currencyStrategy")
  public int addCurrencyStrategy(@RequestBody Map map) {
    return strategyService.addCurrencyStrategy(map);
  }


}